/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.utils;

import java.util.Calendar;
import java.text.SimpleDateFormat;


/**
 * The <code>DateUtils</code> class represents conversions on date. 
 * <p>
 * The methods of <code>DateUtils</code> class will be declared as static, so try to access methods of this class
 * using class name <code>DateUtils</code> instead of creating an object of this class.
 * Here are some  examples of how <code>now</code> method of this class can be used:
 * <p><blockquote><pre>
 *     String currentDate = DateUtils.now("dd.MM.yy  hh:mm:ss");
 *     String currentDate = DateUtils.now("yy.MM.dd hh:mm:ss aaa");
 * </pre></blockquote>
 * <p>
 * @author nurhat
 */
public class DateUtils
{

    /**
     * A function outputs current date according to given date format
     * @param dateFormat  Used to format current date.
     * <ul>
     *    <li>"dd.MM.yy  hh:mm:ss" is for a format like "08.05.20 13:59:14"
     *         </li><li>"yy.MM.dd hh:mm:ss aaa" is for a format like "08.05.20 01:59:51 PM" 
     *         </li>
     * </ul>
     * @return formatted date as string
     * @throws java.lang.IllegalArgumentException thrown when dateformat or input date string
     *                                             is not in correct format
     * @throws java.lang.NullPointerException  thrown when input date string or dateformat is null
     * @throws java.text.ParseException thrown if the beginning of the specified input date string  cannot be parsed.
     * @throws java.lang.Exception
     */
    public static String now(String dateFormat) throws Exception
    {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        return sdf.format(cal.getTime());
    }
}
